package org.aseclipse.core.runtime.classes
{
    import org.aseclipse.core.runtime.Plugin;
    import org.aseclipse.core.runtime.app.AppDescriptor;
    import org.aseclipse.core.runtime.registry.IConfigurationElement;
    import org.aseclipse.core.runtime.registry.IExtension;
    import org.aseclipse.core.runtime.registry.classes.ExtensionRegistry;
    import org.aseclipse.osgi.BundleContext;
    import org.aseclipse.osgi.BundleEngine;
    	  /****
    	  * <extension point="org.aseclipse.ui.application" name="default extension">
    	  *   <applications>
                 <app  label="Modeling Workbench"
                       id="Default">
                    <url pattern="/modeling">
                    </url>
                    <launch-plugin id="org.eclipse.sample.login">
                    	<next-plugin id="org.eclipse.sample.app.homepage"/>
                    </launch-plugin>
                 </app>
        */
        
    public class SystemPlugin extends Plugin
    {
        public static const SYSTEM_PLUGIN_ID:String = "org.aseclipse.ui";
        public static const POINT_ID:String = "application";
        
        private var context:BundleContext;
        public function SystemPlugin() {
            super();
        }

    	override public function start(context:BundleContext):void {
    		super.start(context);
    		this.context = context;
    		var registry:ExtensionRegistry = context.getExtensionRegistry();
    	    var extensions:Array = registry.getExtensionsByPoint(SYSTEM_PLUGIN_ID, POINT_ID);
    	    for each(var ext:IExtension in extensions) {
        	    var configs:Array = ext.getConfigurationElements();
                for each(var config:IConfigurationElement in configs) {
                    if(config.getName() == "application") {
                        var id:String = config.getAttribute("id");
                        var app:AppDescriptor = new AppDescriptor(id, config);
                        BundleEngine.getAppManager().addApp(id, app);
                    }
                }
             }
    		trace("----> SystemPlugin start");
    	}
    	
    	override public function stop(context:BundleContext):void {
    		super.stop(context);
    	}
    		        
    }
}
